package com.vdong.shardingorder.controller;

import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.vdong.base.model.BaseResult;
import com.vdong.shardingorder.entity.VdGoods;
import com.vdong.shardingorder.entity.VdOrder;
import com.vdong.shardingorder.service.IVdOrderService;
import com.vdong.shardingorder.vo.goods.req.ListGoodsReqVO;
import com.vdong.shardingorder.vo.order.req.ListOrderReqVO;
import com.vdong.shardingorder.vo.order.req.SaveOrderReqVO;
import com.vdong.shardingorder.vo.order.resp.OrderDetailRespVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
@Slf4j
@Api(value = "订单基本信息", tags = "订单基本信息")
public class OrderController {

    @Autowired
    private IVdOrderService orderService;


    @PostMapping("/order/save")
    @ApiOperation(value = "添加订单", notes = "添加订单")
    public BaseResult<Boolean> saveOrder(@Valid @RequestBody SaveOrderReqVO req) {
        log.info("添加订单:{}", JSONUtil.toJsonStr(req));
        Boolean bool = orderService.saveOrder(req);
        return new BaseResult<>().data(bool);
    }


    @GetMapping("/order/detail")
    @ApiOperation(value = "订单详情", notes = "订单详情")
    public BaseResult<OrderDetailRespVO> orderDetail(Long userId, Long id) {
        log.info("订单详情:{}", id);
        OrderDetailRespVO vo = orderService.orderDetail(userId, id);
        return new BaseResult<>().data(vo);
    }

    @PostMapping("/order/list")
    @ApiOperation(value = "订单列表", notes = "订单列表")
    public BaseResult<Boolean> listOrder(@Valid @RequestBody ListOrderReqVO req) {
        log.info("订单列表:{}", JSONUtil.toJsonStr(req));
        IPage<VdOrder> page = orderService.listOrder(req);
        return new BaseResult<>().data(page);
    }

}
